<?php
//uu_qunar_use 需要添加tid字段，然后添加数据的时候那边添加上tid，更新表的tid字段，最后根据tid来获取数据，判别往去哪儿还是美团通知
if (!class_exists("go_sql")){
	include("/var/www/html/new/conf/le.je");
	$le=new go_sql();
	$le->connect();
}
$txt=json_encode($_REQUEST);
logfile($txt);

$tid = $_REQUEST['tid'];
$DockingMode = $_REQUEST['DockingMode'];
$tid_aid = $_REQUEST['tid_aid'];
$signkey = $_REQUEST['signkey'];
$supplierIdentity = $_REQUEST['supplierIdentity'];
if($tid){
	$status=0;  // 0,下架 1,上架 2,修改
	if($tid){
		if($DockingMode == 0){ //去哪儿
			file_get_contents("http://10.160.4.140/coop/callback/ProductChangeNotice.php?ids=$tid_aid&status=$status&signkey=$signkey&supplierIdentity=$supplierIdentity");
		}elseif($DockingMode == 1){ //美团
			file_get_contents("http://10.160.4.140/new/d/meituan/MT_ChangeNotice.php?ids=$tid_aid&status=$status&signkey=$signkey&supplierIdentity=$supplierIdentity");
		}elseif($DockingMode == 2){ //百度直达号
			file_get_contents("http://10.160.4.140/new/d/module/api/bd_zhidahao/bdzdh_ProductOff.php?ids=$tid_aid&status=$status&signkey=$signkey&supplierIdentity=$supplierIdentity");
		} 

	}
}
// function logfile($txt){
	// $fp = fopen("/var/www/html/new/d/logs/api/api_product_changenotice/api_product_changecancel".date('Y-m-d').".txt","a");
	// flock($fp, LOCK_EX) ;
	// fwrite($fp,date('Y-m-d H:i:s')."|".$txt."\n");
	// flock($fp, LOCK_UN);
	// fclose($fp);
// }

function logfile($word){
	$path = 'api_product_changecancel';
	$filepath= '/var/www/html/new/d/logs/api/api_product_changenotice/'.$path.'.txt';
	if(file_exists($filepath)){
		$word = date("Y-m-d H:i:s")."|".$word;
		$word = mb_convert_encoding($word, 'GBK', 'UTF-8');
		$maxsize  = 1024*1024*10;
		$filesize = filesize($filepath);
		$filetype = end(explode(".",$filepath));
		$filename = substr($filepath,0,strpos($filepath,'.'));
		if($filesize>$maxsize)
		{
			rename($filepath, $filename.'_'.date('YmdHis').'.'.$filetype);
			$handler=fopen($filepath,'w');
			flock($handler, LOCK_EX) ;
			fwrite($handler,"\n".$word);
			flock($handler, LOCK_UN);
			fclose($handler);
		}
		else
		{
			$fp = fopen('/var/www/html/new/d/logs/api/api_product_changenotice/'.$path.'.txt',"a");
			flock($fp, LOCK_EX);
			fwrite($fp,$word."\n");
			flock($fp, LOCK_UN);
			fclose($fp);
		}
	}else{
		$fp = fopen('/var/www/html/new/d/logs/api/api_product_changenotice/'.$path.'.txt',"a");
		flock($fp, LOCK_EX);
		fwrite($fp,date('Y-m-d H:i:s')."|".$word."\n");
		flock($fp, LOCK_UN);
		fclose($fp);
	}
}
?>
